/*
 * @Description:
 * @Version: 1.0
 * @Autor: chen_yt
 * @Date: 2021-04-19 14:11:57
 * @LastEditors: chen_yt
 * @LastEditTime: 2021-11-22 14:41:49
 */
import Vue from 'vue'
import Websocket from './VuePlugIn.vue'
import store from '@/store'

const FksWebsocketConstructor = Vue.extend(Websocket)

let instance
let seed = 1


const FksWebsocket = function (options = {}) {

  const id = 'fksWs_' + seed++

  instance = new FksWebsocketConstructor({
    data: options
  })
  instance.id = id
  instance.$mount()

  return instance
}



FksWebsocket.close = function (options = {}) {

  if (!store || !options.name) return

  store.commit('DEL_WEBSOCKET_POOL_CLIENT', options.name)

  if (typeof options.onClose === 'function') {
    options.onClose()
  }

}


export default FksWebsocket